'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 金矿相关的接口
 * @author sundbcn@gmail.com (sun debing)
 */

var constantUtil = require('../util/constantUtil');
var buildType = require('../consts/buildType');
var buildConf = require('../config/buildConf');

/**
 * 获金库最大可存储金币
 * @param  {[type]} chest_lv [description]
 * @return {[type]}          [description]
 */
exports.getChestStoreGold = function (chest_lv) {
    // var chest_lv_conf = buildConf.getBuildLvConf(buildType.CHEST, chest_lv);
    // if (!chest_lv_conf) {
    //     return 0;
    // }
    // return chest_lv_conf.gold_store_num;
    return 2000000000;
};

/**
 * 获取能收取的食物
 * @param  {[type]} gain_time_interval [description]
 * @return {[type]}                    [description]
 */
exports.getCanGainGold = function (mine_lv, second, max_gain_gold) {
    var gain_gold = 0;
    var leave_gold = 0;

    // 获取金矿可产出的数量
    var mine_gold_store_num = _getMineStoreGold(mine_lv);

    gain_gold = parseInt(second * _getCanGainGoldEverySecond(mine_lv));

    // 判断是否超过金矿的最大上限
    if (gain_gold > mine_gold_store_num) {
        gain_gold = mine_gold_store_num;
    }

    // 判断是否走过金库的最大上限
    if (gain_gold > max_gain_gold) {
        leave_gold = gain_gold - max_gain_gold;
        gain_gold = max_gain_gold;
    }

    return {
        gain_gold: gain_gold,
        leave_gold: leave_gold
    };
};

/**
 * 获取每秒能收的粮食
 * @param  {[type]} mine_lv [description]
 * @param  {[type]} second  [description]
 * @return {[type]}         [description]
 */
exports.getCanGainGoldEverySecond = function (mine_lv) {
    return _getCanGainGoldEverySecond(mine_lv);
};

/**
 * 获取相应的金币需要多少秒回复
 * @return {[type]} [description]
 */
exports.getGainGoldNeedSecond = function (mine_lv, gold) {
    return gold / _getCanGainGoldEverySecond(mine_lv);
};

var _getCanGainGoldEverySecond = function (mine_lv) {
    // 农场每小时生成出来的粮食
    var mine_gold_product_num = _getMineProductGold(mine_lv);
    return mine_gold_product_num / 3600;
};

/**
 * 农场每个时间段生成出来的粮食
 * @param  {[type]} mine_lv [description]
 * @return {[type]}         [description]
 */
var _getMineProductGold = function (mine_lv) {
    var mine_lv_conf = buildConf.getBuildLvConf(buildType.MINE, mine_lv);
    return mine_lv_conf.product_gold_num;
};

/**
 * 农场最大可生产的粮食
 * @param  {[type]} mine_lv [description]
 * @return {[type]}         [description]
 */
var _getMineStoreGold = function (mine_lv) {
    var mine_lv_conf = buildConf.getBuildLvConf(buildType.MINE, mine_lv);
    return mine_lv_conf.gold_store_num;
};
